package com.kuailexs.sdlvnc;

import org.libsdl.app.SDLActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;

public class MainActivity extends Activity {
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		if(savedInstanceState != null){
			String ip = savedInstanceState.getString("ip");
			String port = savedInstanceState.getString("port");
			String pass = savedInstanceState.getString("pass");
			startSDLActivity(ip, port, pass);
		}
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	}
	@Override
	public void onResume(){
		super.onResume();
	}
	@Override
	public void onRestart() {
		super.onRestart();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
	
	public void onClick(View v) {
		Log.i("点击了", "点击了");
		EditText editText1 = (EditText) findViewById(R.id.editText1);
		//EditText editText2 = (EditText) findViewById(R.id.editText2);
		EditText editText3 = (EditText) findViewById(R.id.editText3);
		String ip = editText1.getText().toString();
		//String port = editText2.getText().toString();
		String pass = editText3.getText().toString();
		startSDLActivity(ip,"",pass);
	}
	public void startSDLActivity(String ip, String port, String pass){
		
		if(ip != null && pass != null){
			Intent intentSDLActivity = new Intent(this, SDLActivity.class);
			intentSDLActivity.putExtra("ip",ip);
			intentSDLActivity.putExtra("port",port);
			intentSDLActivity.putExtra("pass",pass);
			startActivity(intentSDLActivity);
		}
	}
	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		EditText editText1 = (EditText) findViewById(R.id.editText1);
		//EditText editText2 = (EditText) findViewById(R.id.editText2);
		EditText editText3 = (EditText) findViewById(R.id.editText3);
		String ip = editText1.getText().toString();
		//String port = editText2.getText().toString();
		String pass = editText3.getText().toString();
		outState.putString("ip", ip);
		//outState.putString("port", port);
		outState.putString("pass", pass);
	}
}
